<?php 

class Auth extends CI_Controller{
	public $login_error;
	function __construct()
	{
		parent::__construct();
		session_start();
		
	}
	public function login()
	{
		$this->load->library('form_validation');
		$this->form_validation->set_rules('username', 'Username', 'required');
		
				
		if  ($this->form_validation->run() != false) {
			
			$this->load->model('login_model');
			$res = $this
					->login_model
					->verify_user(
						$this->input->post('username'),
						$this->input->post('password')
					);	
			if ($res !== false) {
				$_SESSION['username'] = $this->input->post('username');
				$_SESSION['display_name'] = $res->display_name;
				$_SESSION['group'] = $res->group;
				$_SESSION['user_id'] = $res->user_id;
				redirect('frontend/index');
			}
			else {
				 $login_error = "Can not logging in";
			}
		}
		$this->load->view('login_view');	
	}
	public function logout(){
		session_destroy();
		redirect('auth/login');
	}
}

